﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PhotoGallery.DLL;
using PhotoGallery.Model;
namespace PhotoGallery.BLL
{
    public class PhotoAction
    {
        PictureDataAccess pda = new PictureDataAccess();
        /*首页，显示所有图片*/
        public List<Picture> showAllPhotos() 
        {
             return pda.getAllthePictures();
        }
        /*显示某张图片*/
        public Picture showPic(string pid) 
        {
            return pda.searchpictureById(pid);
        }
        /*显示某个用户的所有图片*/
        public List<Picture> showAllPhotosofSomeOne(string uid) 
        {
            return pda.searchpictureByUsername(uid);
        }
        /*显示某个相册中的所有图片*/
        public List<Picture> showAllPhotosofAlbum(String aid) {
            return pda.searchpictureByAlbumname(aid);
        }
        /*显示某个相册的封面*/
        public Picture showCover(String aid) 
        {
            return pda.getCoverPicbyAlbumId(aid);
        }
        /*根据用户id和相册id查找图片*/
        public Picture getPicbyUidndAid(String uid,String aid) 
        {
            return pda.searchPicbyUidndAid(uid, aid);         
        }
        /*根据用户id和文件名查找图片*/
        public Picture getPicbyUidndFileName(String uid, String filename) 
        {
            return pda.searchPicbyUidndFileName(uid,filename);
        }
        /*上传普通图片*/
        public Picture uploadPictures(String uid, String title,String desp, String aid, String pic)
        {
            pda.insert(uid, title,desp, aid, pic);
            return pda.searchPicbyUidndFileName(uid, title);
        }
        /*上传并设为封面*/
        public Picture uploadPictures(String uid,String title,String desp,String aid,String pic,string state) 
        {
            pda.insert(uid, title, desp,aid, pic,state);
            Picture p = pda.searchPicbyUidndFileName(uid, title);
            pda.setCover(p.Id, aid);
            return pda.getCoverPicbyAlbumId(aid);
        }
        /*修改图片信息*/
        public void modifyPictures(String pid,Picture pic) 
        {
            pda.modifypicture(pid, pic);
        }
        /*删除图片*/
        public void deletePic(String pid) 
        {
            pda.delete(int.Parse(pid));
        }
        /*设为封面图片*/
        public void setcover(String pid, String aid)
        {
            pda.setCover(pid, aid);   
        }
    }
}
